#!/usr/bin/python

"""gen_average.py

this script is
"""

__author__ = 'takahiro'
__version__ = '2014-02-10 1.00 (takahiro)'

import sys
import optparse
import re

usage = "%prog [input file] <num>"
parser = optparse.OptionParser( usage=usage )
parser.parse_args( )

if len( sys.argv ) == 2:
  stream = sys.stdin
  NUM = int(sys.argv[1])
elif len( sys.argv ) == 3:
  stream = open( sys.argv[ 1 ], 'r' )
  NUM = int(sys.argv[2])
else:
  parser.print_help( )
  exit( )

keys = open('format.org', 'r').readlines()[0].rstrip().split(' ')
closes = []

loop = 0
for line in stream:
  array = line.rstrip().split('\t')
  closes.append(int(array[keys.index('close')]))
  while(len(closes) > NUM):
    closes.pop(0)
  if loop < (NUM - 1):
    print 0
  else:
    sum = 0
    for val in closes:
      sum += val
    print (sum/NUM)
  loop += 1

